{extend name="$base" /}
{block name="resources"}
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/member_list.css" />
<script type="text/javascript" src="__STATIC__/My97DatePicker/WdatePicker.js"></script>

{/block}
{block name="main"}
<table class="mytable">
	<tr>
		<th style="text-align: left;">
			<button class="btn-common btn-small" onclick="open_Add_Price()" style="margin:0 5px 0 0 !important;">添加金价</button>
		</th>
</table>
<table class="table-class" >
	<thead>
	<tr align="center">
		<th>ID</th>
		<th>卖出价格</th>
		<th>回购价格</th>
		<th>时间</th>
		<th>操作</th>
	</tr>
	</thead>
	<tbody id="my-table"></tbody>
</table>
{/block}
{block name="script"}
<script type="text/javascript">
    function LoadingInfo(page_index) {
        $.ajax({
            type : "post",
            url : document.location,
            data : {
                "page_index" : page_index,
                "page_size" : $("#showNumber").val()
            },
            success : function(data) {
                if (data["data"].length > 0) {
                    $("#my-table").empty();
                    for (var i = 0; i < data["data"].length; i++) {
                        var html = '';
                        html += '<tr align="center">';
                        html += '<td>'+data["data"][i]["cpid"]+'</td>';
                        html += '<td>'+data["data"][i]["cur_price"]+'</td>';
						html += '<td>'+data["data"][i]["sell_price"]+'</td>';
                        html += '<td>'+data["data"][i]["cur_time"]+'</td>';
                        html += '<td style="text-align: center;"><a onclick="delete_record('+ data["data"][i]["cpid"]+')">删除</a></td>';
                        html += '</tr>';
                        html += '<input type="hidden" id="uid" value="{$uid}"/>';
                        $("#my-table").append(html);
                    }
                } else {
                    var html = '<tr align="center"><td colspan="8">暂无符合条件的数据记录</td></tr>';
                    $("#my-table").html(html);
                }
                initPageData(data["page_count"],data['data'].length,data['total_count']);
                $("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
            }
        });
    }

    /*
	* 添加新记录
	*/
    function open_Add_Price(){

        layer_index = layer.open({
            type: 2,
            title: '添加金价',
            shadeClose: true,
            shade: 0.8,
            area: ['90%', '90%'],
            content: __URL('ADMIN_MAIN/Mine/addCoinPrice')
        });
    }

	// 删除记录
    function delete_record(id){
        $( "#dialog" ).dialog({
            buttons: {
                "确定": function() {
                    $.ajax({
                        type : "post",
                        url : "{:__URL('ADMIN_MAIN/Mine/coinPriceDel')}",
                        data : { "id" : id },
                        dataType : "json",
                        success : function(data) {
                            console.log(data);
                            if(data["code"] > 0 ){
                                //LoadingInfo(1);
								LoadingInfo(getCurrentIndex(id,'#productTbody'));
                                showTip(data["message"],'success');
                                $("#chek_all").prop("checked", false);
                            }else{
                                showTip(data["message"],'error');
                            }
                        }
                    });
                    $(this).dialog('close');
                },
                "取消,#e57373": function() {
                    $(this).dialog('close');
                },
            },
            contentText:"确定要删除吗？",
        });
    }
</script>
{/block}